package shiqi.util.stream;

/**
 * @author shiqi
 * @version 1.0.0
 * @ClassName MockStream1.java
 * @Description
 * @createTime 2022-05-07
 */
public class MockStream1 {

    public static void main(String[] args) {

        Person bravo = new Person("bravo", 18);

        // 1.匿名对象，调用它的test()方法
        Predicate<Person> predicate1 = new Predicate<Person>() {
            @Override
            public boolean test(Person person) {
                return person.getAge() < 18;
            }
        };
        myPrint(bravo, predicate1); // false

        // 2.Lambda表达式，调用它的test()方法。
        // 按照Lambda表达式的标准，只要你是个函数式接口，那么就可以接收Lambda表达式
        Predicate<Person> predicate2 = person -> person.getAge() == 18;
        myPrint(bravo, predicate2); // true
    }

    public static void myPrint(Person person, Predicate<Person> filter) {
        if (filter.test(person)) {
            System.out.println("true");
        } else {
            System.out.println("false");
        }
    }
}
